<cfcomponent displayname="CrafterMediaItem" accessors="yes" output="no" hint="Represents a standard media item inside the Full Sail / Crafter universe.">


	<!--- Properties --->
	<cfproperty name="code" type="string" />
	<cfproperty name="height" type="numeric" />
	<cfproperty name="width" type="numeric" />
	<cfproperty name="alt" type="string" />
	<cfproperty name="title" type="string" />
	<cfproperty name="caption" type="string" />
	<cfproperty name="runtime" type="string" />
	<cfproperty name="isVideo" type="boolean" />
	<cfproperty name="path" type="string" />
	<cfproperty name="alfrescoRoot" type="string" />
	<cfproperty name="isLoaded" type="boolean" />
	
	
	<!--- init() --->
	<cffunction name="init" access="public" returntype="any" output="no">
		<cfargument name="rootPath" type="string" required="yes" />
		<cfscript>
			setAlfrescoRoot(arguments.rootPath);
			setIsLoaded(false);
			setCode("");
			setHeight(0);
			setWidth(0);
			setAlt("");
			setTitle("");
			setCaption("");
			setRuntime("");
			setIsVideo(false);
			setPath("");
			return this;
		</cfscript>
	</cffunction>
	
	
	<!--- loadFromXml() --->
	<cffunction name="loadFromXml" access="public" returntype="any" output="no">
		<cfargument name="oXML" type="any" required="yes" />
		<cfscript>
			
			// Simplify values
			local.code = arguments.oXML.XmlChildren[1].XmlText;
			local.height = arguments.oXML.XmlChildren[2].XmlText;
			local.width = arguments.oXML.XmlChildren[3].XmlText;
			local.alt = arguments.oXML.XmlChildren[4].XmlText;
			local.title = arguments.oXML.XmlChildren[5].XmlText;
			local.caption = arguments.oXML.XmlChildren[6].XmlText;
			local.runtime = arguments.oXML.XmlChildren[7].XmlText;
			local.isVideo = arguments.oXML.XmlChildren[8].XmlText;
			local.path = arguments.oXML.XmlChildren[9].XmlText;
			
			// Set values
			setCode(arguments.oXML.XmlChildren[1].XmlText);
			setAlt(arguments.oXML.XmlChildren[4].XmlText);
			setTitle(arguments.oXML.XmlChildren[5].XmlText);
			setCaption(arguments.oXML.XmlChildren[6].XmlText);
			setRuntime(arguments.oXML.XmlChildren[7].XmlText);
			setPath(arguments.oXML.XmlChildren[9].XmlText);
			
			// Run checks on numeric and boolean values
			if (IsNumeric(local.height)) {
				setHeight(local.height);
			}
			
			if (IsNumeric(local.width)) {
				setWidth(local.width);
			}
			
			if (IsBoolean(local.isVideo)) {
				setIsVideo(local.isVideo);
			}
			
			// Mark as loaded and return
			setIsLoaded(true);
			return this;
			
		</cfscript>
	</cffunction>
	
	
	<cffunction name="getFullPath" access="public" returntype="string" output="no">
		<cfreturn getAlfrescoRoot() & getPath() />
	</cffunction>
	
	
	<cffunction name="getPathOrNothing" access="public" returntype="string" output="no">
		<cfif (getPath() EQ "") OR (getPath() EQ getAlfrescoRoot())>
			<cfreturn "" />
		<cfelse>
			<cfreturn getFullPath() />
		</cfif>
	</cffunction>

	
</cfcomponent>